package com.calm.editor.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import com.google.gson.annotations.Expose;

@Entity
@Table(name="XHTML_NODE_ELEMENT")
public class NodeElement {
	
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.TABLE,generator="XHTML_ELEMENT_ID")
	@TableGenerator(name = "XHTML_ELEMENT_ID", pkColumnValue = "XHTML_ELEMENT_ID" , table = "ID_SEQUENCE", pkColumnName = "ID_KEY", valueColumnName = "VALUE", allocationSize = 1)
	private Integer id;
	
	@Column(name = "ELEMENT_ID")
	private String elementId;
	
	@Column(name = "TAG_NAME")
	private String tagName;
	
	@Column(name = "DELETE_CLASS")
	private String deleteClass;
	
	@Column(name = "NAMESPACE")
	private String namespace;
	
	@ManyToOne
	@JoinColumn(name = "PARENT_ID")
	@Expose(serialize = false)
	private NodeElement parent;
	
	@ManyToOne
	@JoinColumn(name = "PAGE_ID")
	@Expose(serialize = false)
	private Page page;
	
	@OneToMany(cascade=CascadeType.REMOVE)
	@JoinColumn(name="PARENT_ID")
	@Expose(serialize = false)
	private List<NodeElement> children;
//	@OneToMany
//	@JoinColumn(name = "ELEMENT_ID")
//	@Expose(serialize = false)
//	private List<ElementAttribute<NodeElement>> attrs;
	
//	public List<ElementAttribute<NodeElement>> getAttrs() {
//		return attrs;
//	}
//
//	public void setAttrs(List<ElementAttribute<NodeElement>> attrs) {
//		this.attrs = attrs;
//	}
	
	public NodeElement getParent() {
		return parent;
	}

	public void setParent(NodeElement parent) {
		this.parent = parent;
	}

	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}

	public List<NodeElement> getChildren() {
		return children;
	}

	public void setChildren(List<NodeElement> children) {
		this.children = children;
	}
	public Integer getPageId(){
		if(page!=null){
			return page.getId();
		}
		return null;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getElementId() {
		return elementId;
	}

	public void setElementId(String elementId) {
		this.elementId = elementId;
	}

	public String getTagName() {
		return tagName;
	}

	public void setTagName(String tagName) {
		this.tagName = tagName;
	}

	public String getDeleteClass() {
		return deleteClass;
	}

	public void setDeleteClass(String deleteClass) {
		this.deleteClass = deleteClass;
	}

	public String getNamespace() {
		return namespace;
	}

	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}
	
//	public Integer getParentId(){
//		if(parent!=null){
//			return parent.getId();
//		}
//		return null;
//	}
	
}
